// pages/strategy/strategyDetails/strategyDetails.js
import {
  maybeLike,
  getAttackK,
  lookAttack
} from '../../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    titlename:"",
    attack_content: [],
    click_num: "",
    notice_content: [],
    maybeData: {
    },
    gonglv: {
      id: "",
      attack_id: "",
    },
    maybeListData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    var data = JSON.parse(options.data)
    let titlename = data.attack_name
    let attack_content = data.attack_content
    let click_num = data.click_num
    let notice_content = data.notice_content
    let create_time = data.create_time
    that.setData({
      titlename: data.attack_name,
      create_time: data.create_time,
      attack_content: data.attack_content,
      notice_content: data.notice_content,
      click_num: data.click_num
    })
    that.maybeLove()
  },
  //可能喜欢
  maybeLove() {
    maybeLike(this.data.maybeData).then(res => {
      // let showActivitiesMAY = "showActivities.maybeListData"
      this.setData({
        maybeListData: res.datas
        //  [showActivitiesMAY]: res.datas
      })
    })
  },
  previewIamge(event) {
    const nowIndex = event.currentTarget.dataset.id;
    const imgList = event.currentTarget.dataset.list
    wx.previewImage({
      current: imgList[nowIndex], //当前预览的图片
      urls: imgList, //所有要预览的图片
    })
  },
  //回到顶部
  tiaozhaun(e){
    var info = e.currentTarget.dataset.id;
    var id = 'gonglv.id';
    var attack_id = 'gonglv.attack_id'
    this.setData({
      [id]: e.currentTarget.dataset.id.id,
      [attack_id]: e.currentTarget.dataset.id.attack_id
    })
    let gonglv = JSON.stringify(this.data.gonglv)
    wx.redirectTo({
      url: '../details/details?data=' + gonglv ,
    })
  },
  //相关攻略
  lookAttacktt() {
    lookAttack(this.data.gonglv).then(res => {
      if (res.code === 200) {
        this.setData({
          titlename: res.datas.attack_name,
          create_time: res.datas.create_time,
          attack_content: res.datas.attack_content,
          price: res.datas.price,
          oldPrice: res.datas.consult_price,
          notice_content: res.datas.notice_content,
          click_num: res.datas.click_num,
          imgs: res.datas.imgs,
          is_sell_safe: res.datas.is_sell_safe,
          shppImg: res.datas.imgs[0],
          shppTitle: res.datas.attack_name
        })
        if (wx.pageScrollTo) {
          wx.pageScrollTo({
            scrollTop: 0
          })
        }
      } else {
        wx.showToast({
          title: res.msg,
          duration: 3000,
          icon: none
        })
      }
    })
  },
  getList() {
    //wx.showLoading({ title: '加载中' });
    getAttackK(this.data.getCateIIData).then(res => {
      // if (res.code == 200) {
      //   this.setData({
      //     arrayList: this.data.arrayList.concat(res.datas.list)
      //   })
      //   if (res.datas.more == false) {
      //     this.setData({
      //       isdata: false
      //     })
      //   } else {
      //     this.setData({
      //       isdata: true
      //     })
      //   }
      // } else {
      //   this.setData({
      //     arrayList: []
      //   })
      // }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

 

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  aa(e) {
  }
})